package com.hxh.wechat.api

import com.hxh.wechat.util.HttpUtil
import okhttp3.Call
import com.hxh.wechat.util.toFormBody
import okhttp3.FormBody

class UserApi {
    companion object {
        data class User(val username: String, val password: String, val cid: String)

        /**
         * 用户模块一级路径
         */
        private const val BASE_URL: String = "user/";

        /**
         * 用户模块二级路径
         */

        //注册登录接口
        private const val LOGIN: String = "login";
        private const val MY_FRIENDS: String = "myFriends";
        private const val QUERY_UN_SIGN_MSG: String = "queryUnSignMsg";
        private const val SIGN_MESSAGE: String = "signMessage";

        // 我的好友
        fun myFriends(id: String): Call? {
            val path = BASE_URL + MY_FRIENDS
            var formBody = FormBody.Builder().add("id", id).build()
            return HttpUtil.post(path, formBody)
        }

        // 登录注册接口
        fun login(username: String, password: String, cid: String): Call? {
            var user = User(username, password, cid)
            val path = BASE_URL + LOGIN
            return HttpUtil.post(path, user.toFormBody())
        }

        // 查看未签收消息
        fun queryUnSignMsg(myId: String): Call? {
            val path = BASE_URL + QUERY_UN_SIGN_MSG
            var formBody = FormBody.Builder().add("myId", myId).build()
            return HttpUtil.post(path, formBody)
        }
        // 签收消息
        fun signMessage(msgId: String): Call? {
            val path = BASE_URL + SIGN_MESSAGE
            var formBody = FormBody.Builder().add("msgId", msgId).build()
            return HttpUtil.post(path, formBody)
        }
    }
}